class SqlUtil {
    constructor() {

    }
    static formatDBObj(dbObj, config) {
        let obj = {};
        //找到需要添加的自定义属性
        let selfKeys = [];
        Object.keys(config).forEach(function (key) {
            if (key.startsWith("self_")) {
                selfKeys.push(key.split("_")[1]);
            }
        });
        Object.keys(dbObj).forEach(function (key) {
            if (config[key]) {
                obj[config[key]] = dbObj[key];
            } else {
                obj[key] = dbObj[key];
            }
            selfKeys.forEach(function (selfKey) {
                obj[selfKey] = config["self_" + selfKey]["default"];
            });
        });
        return obj;
    }
    static formatDBList(list, config) {
        return list.map(function (val) {
            return SqlUtil.formatDBObj(val, config);
        })
    }
}
module.exports = SqlUtil;